package com.lmc.health.rate;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.lmc.R;
import com.lmc.adapter.AnalyzeFragmentAdapter;
import com.lmc.entity.HeartRate;
import com.lmc.entity.HeartType;
import com.lmc.util.DateFormatUtil;
import com.lmc.util.JsonManager;
import com.lmc.view.BrokenLine;
import com.qxzn.app.api.api.HttpRequest;

import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 心率数据分析
 */
public class AnalyzeFragment extends Fragment implements View.OnClickListener {

    private BrokenLine broken_line;
    private Button bt_7;
    private Button bt_30;
    private TextView name;
    private TextView num;
    private GridView grid_view;
    private List<HeartRate.DataBean.ResultcountBean> count_list = new ArrayList<>();
    private AnalyzeFragmentAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.lmc_fragment_analyze, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        broken_line = (BrokenLine) view.findViewById(R.id.broken_line);
        bt_7 = (Button) view.findViewById(R.id.bt_7);
        bt_30 = (Button) view.findViewById(R.id.bt_30);
        name = view.findViewById(R.id.name);
        num = view.findViewById(R.id.num);
        grid_view = view.findViewById(R.id.grid_view);

        bt_7.setOnClickListener(this);
        bt_30.setOnClickListener(this);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        adapter = new AnalyzeFragmentAdapter(getContext(), count_list);
        grid_view.setAdapter(adapter);
        Get(7);
    }

    public void  hideDataDialog(){
        broken_line.hideDetails();
    }
    private void Get(final int day) {

        //后台要求先请求获取测量类型
        final HeartRateActivity activity = (HeartRateActivity) getActivity();
        name.setText(activity.health.getName() + "值（" + activity.health.getUnit() + "）");

        JSONObject params = new JSONObject();
        params.put("device_id", activity.health.getDevice_id());
        params.put("username", activity.health.getUsername());
        params.put("datetime", String.valueOf(day));
        params.put("type", activity.health.getTname());
        HttpRequest.getService().getDataByType(HttpRequest.getDefaultBody(params)).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    String json = response.body().string();
                    Log.e("-----------", "获取数据返回：" + json);
                    HeartRate heartRate = JsonManager.parseJson(json, HeartRate.class);
                    num.setText(activity.health.getName() + "测量总数：" + heartRate.getData().getTotal());
                    count_list.clear();
                    count_list.addAll(heartRate.getData().getResultcount());
                    adapter.notifyDataSetChanged();
                    BrokenLine(heartRate, day);
                } catch (Exception e) {
                }

            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
            }
        });


//
//        JSONObject params = new JSONObject();
//        HttpRequest.getService().getTypeList(HttpRequest.getDefaultBody(params)).enqueue(new Callback<ResponseBody>() {
//            @Override
//            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                try {
//                    String json = response.body().string();
//                    HeartType type = JsonManager.parseJson(json, HeartType.class);
//                    for (HeartType.DataBean dataBean : type.getData()) {
//                        if (dataBean.getDetection_type().equals(activity.health.getName())) {
//                            JSONObject params = new JSONObject();
//                            params.put("device_id", activity.health.getDevice_id());
//                            params.put("username", activity.health.getUsername());
//                            params.put("datetime", String.valueOf(day));
//                            params.put("type", dataBean.getConnection_table());
//                            HttpRequest.getService().getDataByType(HttpRequest.getDefaultBody(params)).enqueue(new Callback<ResponseBody>() {
//                                @Override
//                                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                                    try {
//                                        String json = response.body().string();
//                                        Log.e("-----------", "获取数据返回：" + json);
//                                        HeartRate heartRate = JsonManager.parseJson(json, HeartRate.class);
//                                        num.setText("测量总数：" + heartRate.getData().getTotal());
//                                        count_list.clear();
//                                        count_list.addAll(heartRate.getData().getResultcount());
//                                        adapter.notifyDataSetChanged();
//                                        BrokenLine(heartRate, day);
//                                    } catch (Exception e) {
//                                    }
//
//                                }
//
//                                @Override
//                                public void onFailure(Call<ResponseBody> call, Throwable t) {
//                                }
//                            });
//
//                            break;
//                        }
//
//                    }
//
//                } catch (Exception e) {
//                }
//
//            }
//
//            @Override
//            public void onFailure(Call<ResponseBody> call, Throwable t) {
//            }
//        });
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.bt_7) {
            bt_7.setBackgroundResource(R.drawable.lmc_a_b_g);
            bt_30.setBackgroundResource(R.drawable.lmc_a_b_w);
            bt_7.setTextColor(Color.parseColor("#ffffff"));
            bt_30.setTextColor(Color.parseColor("#FF2A8CFF"));
            Get(7);
        } else if (id == R.id.bt_30) {
            bt_7.setBackgroundResource(R.drawable.lmc_a_b_g_2);
            bt_30.setBackgroundResource(R.drawable.lmc_a_b_w_2);
            bt_7.setTextColor(Color.parseColor("#FF2A8CFF"));
            bt_30.setTextColor(Color.parseColor("#ffffff"));
            Get(30);
        }
    }


    private void BrokenLine(int day) {
        if (day == 7) {
            //显示7天数据
            broken_line.setxLabel(new String[]{"05/07", "05/08", "05/09", "05/10", "05/11", "05/12", "05/13", "今天"});
            broken_line.setyLabel(new String[]{"0", "20", "40", "60", "80", "100", "120"});
            broken_line.setData(new String[]{"0", "0", "78", "68", "10", "75", "55", "60"});
            broken_line.invalidate();
            broken_line.hideDetails();
        } else {
            //显示30天数据
            broken_line.setxLabel(new String[]{"05/01", "05/08", "05/15", "05/21", "05/28", "05/31", "今天"});
            broken_line.setyLabel(new String[]{"0", "20", "40", "60", "80"});
            broken_line.setData(new String[]{"18", "58", "13", "50", "68", "83", "55"});
            broken_line.invalidate();
            broken_line.hideDetails();
        }
    }

    private void BrokenLine(HeartRate heartRate, int day) {
        List<HeartRate.DataBean.ResultBean> result = heartRate.getData().getResult();
        if (result.size() == 0) {
            //为空时给出默认图表
            switch (day) {
                case 7://7天的数据
                    String[] xl = new String[7];
                    xl[6] = DateFormatUtil.forString(DateFormatUtil.getTime(), "MM/dd");
                    xl[5] = DateFormatUtil.forString(DateFormatUtil.getTime() - (1 * 24 * 60 * 60 * 1000), "MM/dd");
                    xl[4] = DateFormatUtil.forString(DateFormatUtil.getTime() - (2 * 24 * 60 * 60 * 1000), "MM/dd");
                    xl[3] = DateFormatUtil.forString(DateFormatUtil.getTime() - (3 * 24 * 60 * 60 * 1000), "MM/dd");
                    xl[2] = DateFormatUtil.forString(DateFormatUtil.getTime() - (4 * 24 * 60 * 60 * 1000), "MM/dd");
                    xl[1] = DateFormatUtil.forString(DateFormatUtil.getTime() - (5 * 24 * 60 * 60 * 1000), "MM/dd");
                    xl[0] = DateFormatUtil.forString(DateFormatUtil.getTime() - (6 * 24 * 60 * 60 * 1000), "MM/dd");
                    String[] yl = new String[]{"0", "20", "40", "60", "80"};
                    String[] data = new String[]{"0", "0", "0", "0", "0", "0", "0"};
                    broken_line.setxLabel(xl);
                    broken_line.setyLabel(yl);
                    broken_line.setData(data);
                    break;
                default://30天数据
                    String[] xl_30 = new String[30];
                    xl_30[29] = DateFormatUtil.forString(DateFormatUtil.getTime(), "MM/dd");
                    xl_30[28] = DateFormatUtil.forString(DateFormatUtil.getTime() - (1l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[27] = DateFormatUtil.forString(DateFormatUtil.getTime() - (2l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[26] = DateFormatUtil.forString(DateFormatUtil.getTime() - (3l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[25] = DateFormatUtil.forString(DateFormatUtil.getTime() - (4l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[24] = DateFormatUtil.forString(DateFormatUtil.getTime() - (5l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[23] = DateFormatUtil.forString(DateFormatUtil.getTime() - (6l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[22] = DateFormatUtil.forString(DateFormatUtil.getTime() - (7l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[21] = DateFormatUtil.forString(DateFormatUtil.getTime() - (8l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[20] = DateFormatUtil.forString(DateFormatUtil.getTime() - (9l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[19] = DateFormatUtil.forString(DateFormatUtil.getTime() - (10l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[18] = DateFormatUtil.forString(DateFormatUtil.getTime() - (11l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[17] = DateFormatUtil.forString(DateFormatUtil.getTime() - (12l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[16] = DateFormatUtil.forString(DateFormatUtil.getTime() - (13l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[15] = DateFormatUtil.forString(DateFormatUtil.getTime() - (14l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[14] = DateFormatUtil.forString(DateFormatUtil.getTime() - (15l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[13] = DateFormatUtil.forString(DateFormatUtil.getTime() - (16l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[12] = DateFormatUtil.forString(DateFormatUtil.getTime() - (17l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[11] = DateFormatUtil.forString(DateFormatUtil.getTime() - (18l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[10] = DateFormatUtil.forString(DateFormatUtil.getTime() - (19l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[9] = DateFormatUtil.forString(DateFormatUtil.getTime() - (20l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[8] = DateFormatUtil.forString(DateFormatUtil.getTime() - (21l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[7] = DateFormatUtil.forString(DateFormatUtil.getTime() - (22l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[6] = DateFormatUtil.forString(DateFormatUtil.getTime() - (23l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[5] = DateFormatUtil.forString(DateFormatUtil.getTime() - (24l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[4] = DateFormatUtil.forString(DateFormatUtil.getTime() - (25l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[3] = DateFormatUtil.forString(DateFormatUtil.getTime() - (26l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[2] = DateFormatUtil.forString(DateFormatUtil.getTime() - (27l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[1] = DateFormatUtil.forString(DateFormatUtil.getTime() - (28l * 24 * 60 * 60 * 1000), "MM/dd");
                    xl_30[0] = DateFormatUtil.forString(DateFormatUtil.getTime() - (29l * 24 * 60 * 60 * 1000), "MM/dd");
                    String[] yl_30 = new String[]{"0", "20", "40", "60", "80"};
                    String[] data_30 = new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
                    for (int i = 0; i < 30; i++) {
                        if (i % 7 != 0) {
                            xl_30[i] = "";
                        }
                    }
                    broken_line.setxLabel(xl_30);
                    broken_line.setyLabel(yl_30);
                    broken_line.setData(data_30);
                    break;
            }

            broken_line.invalidate();
            broken_line.hideDetails();
            return;
        }

        //计算有几个值
        int num = result.get(0).getValue().split("-").length;

        switch (day) {
            case 7://7天的数据
                String[] xl = new String[7];
                xl[6] = DateFormatUtil.forString(DateFormatUtil.getTime(), "MM/dd");
                xl[5] = DateFormatUtil.forString(DateFormatUtil.getTime() - (1 * 24 * 60 * 60 * 1000), "MM/dd");
                xl[4] = DateFormatUtil.forString(DateFormatUtil.getTime() - (2 * 24 * 60 * 60 * 1000), "MM/dd");
                xl[3] = DateFormatUtil.forString(DateFormatUtil.getTime() - (3 * 24 * 60 * 60 * 1000), "MM/dd");
                xl[2] = DateFormatUtil.forString(DateFormatUtil.getTime() - (4 * 24 * 60 * 60 * 1000), "MM/dd");
                xl[1] = DateFormatUtil.forString(DateFormatUtil.getTime() - (5 * 24 * 60 * 60 * 1000), "MM/dd");
                xl[0] = DateFormatUtil.forString(DateFormatUtil.getTime() - (6 * 24 * 60 * 60 * 1000), "MM/dd");

                String[] yl = new String[]{"0", "20", "40", "60", "80"};
                String[] data = new String[]{"0", "0", "0", "0", "0", "0", "0"};
                String[] data2 = new String[]{"0", "0", "0", "0", "0", "0", "0"};
                String[] data3 = new String[]{"0", "0", "0", "0", "0", "0", "0"};

                for (int i = 0; i < result.size(); i++) {
                    HeartRate.DataBean.ResultBean bean = result.get(i);
                    String sd = DateFormatUtil.forString(bean.getDate(), "MM/dd");
                    for (int j = 0; j < xl.length; j++) {
                        if (xl[j].equals(sd)) {
                            if (num == 1) {
                                data[j] = bean.getValue();
                            } else if (num == 2) {
                                String[] split = bean.getValue().split("-");
                                data[j] = split[0];
                                data2[j] = split[1];
                            } else if (num == 3) {
                                String[] split = bean.getValue().split("-");
                                data[j] = split[0];
                                data2[j] = split[1];
                                data3[j] = split[2];
                            }
                        }
                    }
                }
                //根据数值的最高值计算出Y坐标的最高值及平均值
                float sum = new Float(data[0]);//假设第一个元素是最大值
                for (int i = 0; i < data.length; i++) {
                    if (sum < new Float(data[i])) {//数组中的元素跟sum比较，比sum大就把它赋值给sum作为新的比较值
                        sum = new Float(data[i]);
                    }
                }
                sum = (sum + (10 - (sum % 10))) * 2;
                yl[4] = String.valueOf(sum / 5 * 4);
                yl[3] = String.valueOf(sum / 5 * 3);
                yl[2] = String.valueOf(sum / 5 * 2);
                yl[1] = String.valueOf(sum / 5 * 1);
                yl[0] = String.valueOf(0);
                xl[6] = "今天";
                broken_line.setxLabel(xl);
                broken_line.setyLabel(yl);
                if (num == 1) {

                    broken_line.setData(data);
                } else if (num == 2) {
                    broken_line.setData(data, data2);
                } else if (num == 3) {
                    broken_line.setData(data, data2, data3);
                }
                break;
            default://30天数据

                String[] xl_30 = new String[30];
                xl_30[29] = DateFormatUtil.forString(DateFormatUtil.getTime(), "MM/dd");
                xl_30[28] = DateFormatUtil.forString(DateFormatUtil.getTime() - (1l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[27] = DateFormatUtil.forString(DateFormatUtil.getTime() - (2l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[26] = DateFormatUtil.forString(DateFormatUtil.getTime() - (3l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[25] = DateFormatUtil.forString(DateFormatUtil.getTime() - (4l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[24] = DateFormatUtil.forString(DateFormatUtil.getTime() - (5l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[23] = DateFormatUtil.forString(DateFormatUtil.getTime() - (6l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[22] = DateFormatUtil.forString(DateFormatUtil.getTime() - (7l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[21] = DateFormatUtil.forString(DateFormatUtil.getTime() - (8l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[20] = DateFormatUtil.forString(DateFormatUtil.getTime() - (9l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[19] = DateFormatUtil.forString(DateFormatUtil.getTime() - (10l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[18] = DateFormatUtil.forString(DateFormatUtil.getTime() - (11l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[17] = DateFormatUtil.forString(DateFormatUtil.getTime() - (12l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[16] = DateFormatUtil.forString(DateFormatUtil.getTime() - (13l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[15] = DateFormatUtil.forString(DateFormatUtil.getTime() - (14l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[14] = DateFormatUtil.forString(DateFormatUtil.getTime() - (15l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[13] = DateFormatUtil.forString(DateFormatUtil.getTime() - (16l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[12] = DateFormatUtil.forString(DateFormatUtil.getTime() - (17l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[11] = DateFormatUtil.forString(DateFormatUtil.getTime() - (18l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[10] = DateFormatUtil.forString(DateFormatUtil.getTime() - (19l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[9] = DateFormatUtil.forString(DateFormatUtil.getTime() - (20l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[8] = DateFormatUtil.forString(DateFormatUtil.getTime() - (21l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[7] = DateFormatUtil.forString(DateFormatUtil.getTime() - (22l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[6] = DateFormatUtil.forString(DateFormatUtil.getTime() - (23l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[5] = DateFormatUtil.forString(DateFormatUtil.getTime() - (24l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[4] = DateFormatUtil.forString(DateFormatUtil.getTime() - (25l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[3] = DateFormatUtil.forString(DateFormatUtil.getTime() - (26l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[2] = DateFormatUtil.forString(DateFormatUtil.getTime() - (27l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[1] = DateFormatUtil.forString(DateFormatUtil.getTime() - (28l * 24 * 60 * 60 * 1000), "MM/dd");
                xl_30[0] = DateFormatUtil.forString(DateFormatUtil.getTime() - (29l * 24 * 60 * 60 * 1000), "MM/dd");

                String[] yl_30 = new String[]{"0", "20", "40", "60", "80"};
                String[] data_30 = new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
                String[] data_30_2 = new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
                String[] data_30_3 = new String[]{"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
                for (int i = 0; i < result.size(); i++) {
                    HeartRate.DataBean.ResultBean bean = result.get(i);
                    String sd = DateFormatUtil.forString(bean.getDate(), "MM/dd");
                    for (int j = 0; j < xl_30.length; j++) {
                        if (xl_30[j].equals(sd)) {
                            if (num == 1) {
                                data_30[j] = bean.getValue();
                            } else if (num == 2) {
                                String[] split = bean.getValue().split("-");
                                data_30[j] = split[0];
                                data_30_2[j] = split[1];
                            } else if (num == 3) {
                                String[] split = bean.getValue().split("-");
                                data_30[j] = split[0];
                                data_30_2[j] = split[1];
                                data_30_3[j] = split[2];
                            }
                        }

                    }
                }
                //根据数值的最高值计算出Y坐标的最高值及平均值
                float sum_30 = new Float(data_30[0]);//假设第一个元素是最大值
                for (int i = 0; i < data_30.length; i++) {
                    if (sum_30 < new Float(data_30[i])) {//数组中的元素跟sum比较，比sum大就把它赋值给sum作为新的比较值
                        sum_30 = new Float(data_30[i]);
                    }
                }
                sum_30 = (sum_30 + (10 - (sum_30 % 10))) * 2;
                yl_30[4] = String.valueOf(sum_30 / 5 * 4);
                yl_30[3] = String.valueOf(sum_30 / 5 * 3);
                yl_30[2] = String.valueOf(sum_30 / 5 * 2);
                yl_30[1] = String.valueOf(sum_30 / 5 * 1);
                yl_30[0] = String.valueOf(0);

                for (int i = 0; i < 30; i++) {
                    if (i % 7 != 0) {
                        xl_30[i] = "";
                    }
                }

                broken_line.setxLabel(xl_30);
                broken_line.setyLabel(yl_30);

                if (num == 1) {
                    broken_line.setData(data_30);
                } else if (num == 2) {
                    broken_line.setData(data_30, data_30_2);
                } else if (num == 3) {
                    broken_line.setData(data_30, data_30_2, data_30_3);
                }

                break;
        }

        broken_line.invalidate();
        broken_line.hideDetails();
    }


}
